'use strict';

angular.module('app').controller('authostatisController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal',
    function($rootScope, $scope, $http, $state,toaster,$modal) {
        $scope.title = '授权统计';
        $scope.loading = false;
        var Nowdate=new Date();
        var years = Number(Nowdate.getFullYear());
        var Month=Number(Nowdate.getMonth())+1;
        if(Month<10){
            Month = '0'+Month
        }
        var nowMonth = years+''+Month;//获取当前年月
        $('#time').attr('placeholder','请输入年月如  '+nowMonth)
        getpeple({'month':nowMonth});//向后台申请数据
        //查询请求数据
        $scope.searchBtn = function () {
            var obj = $('#time').val();
            if(obj==''){
                obj = nowMonth;
                console.log(nowMonth);
                getpeple({'month':obj});
            }else{
                console.log(obj);
                getpeple({'month':obj});
            }
            
        }
        function getpeple(obj) {
        $scope.loading = true;
        console.log(obj)
        var myChart = echarts.init(document.getElementById('authoStatis'));
        // 异步加载数据
        $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType:'application/json;charset=UTF-8',
            url : '/dac/report/person/auth',
            data: angular.toJson(obj)
        }).then(function (result) {
            $scope.loading = false;
            console.log(result)
            var option = {
                // tooltip: {
                //     trigger: 'axis',
                //     axisPointer: {
                //         type: 'cross',
                //         crossStyle: {
                //             color: '#999'
                //         }
                //     }
                // },
                toolbox: {
                    feature: {
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                legend: {
                    data: ['在线授权', '临时授权'],
                },
                xAxis: [
                    {
                        type: 'category',
                        data: result.data.regionName,
                        axisPointer: {
                            type: 'shadow'
                        },
                        axisLabel:{
                            interval:0,
                            rotate:45//倾斜度 -90 至 90 默认为0
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '人数',
                        min: 0,
                        interval: '',
                        axisLabel: {
                            formatter: '{value} 人'
                        }
                    },

                ],
                series: [
                    {
                        name: '在线授权',
                        type: 'bar',
                        barWidth:'20px',
                        data: result.data.onlineAuthCount,
                        itemStyle: {
                            normal: {color: '#6490f2'}
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'top',
                                color:'#555'
                            }
                        },
                    },
                    {
                        name: '临时授权',
                        type: 'bar',
                        barWidth:'20px',
                        data: result.data.tempAuthCount,
                        itemStyle: {
                            normal: {color: '#ec0e6e'},
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'top',
                                color:'#555'
                            }
                        },
                    }
                ]

            };
            myChart.setOption(option);
        })
    }
    }

]);

